/**
 * 获取多模块的default
 *modulesFiles === require.context(directory,useSubdirectories,regExp)
 *directory {String} -读取文件的路径
 *useSubdirectories {Boolean} -是否遍历文件的子目录
 *regExp {RegExp} -匹配文件的正则
 */
export const getExportObject = function(modulesFiles, isDefault) {
    const modules = modulesFiles.keys().reduce((modules, modulePath) => {
        const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1');
        const exportObject = { ...modulesFiles(modulePath) };
        const defaultObject = exportObject.default;
        delete exportObject.default;
        modules[moduleName] = isDefault === undefined ? { defaultObject, exportObject } : isDefault ? defaultObject : exportObject;
        return modules;
    }, {});
    return modules;
};
//Object.assign--对象内部对象可融合
export const assignBest = function(target, ...sourceList) {
    if (sourceList.length === 0) return target;
    let [source, ...sourceArr] = sourceList;
    for (const key of Object.keys(source)) {
        if (Object.prototype.toString.call(target[key]) === '[object Object]' && Object.prototype.toString.call(source[key]) === '[object Object]') {
            assignBest(target[key], source[key]);
        } else {
            target[key] = source[key];
        }
    }
    assignBest(target, ...sourceArr);
    return target;
};